import java.util.LinkedList;

import javax.swing.JOptionPane;

public class PledgeGame extends PledgeFunc {

	static LinkedList<Pledge> currentPledges = new LinkedList<Pledge>();
	static int round = 1;
	static int players = 0;
	static double alpha = 0;
	static double A = 0;
	static double B = 0;
	
	public static void main(String[] args) {
		
		new Console();
		
		setupGame();
		setupPledges(currentPledges, players);
				
		for(int i = 0; i < round; i++)
		{
			preparePledges(currentPledges);
			System.out.println("\nROUND " + (i+1));
			performRound(currentPledges,A,B,alpha);
			
			JOptionPane.showMessageDialog(null, "Round results printed in console!\nLook at them now before pressing 'OK'!",
					"SUCCESS!", JOptionPane.NO_OPTION);
		}
	}
	
	public static void setupGame() {
		String info;
		
		info = JOptionPane.showInputDialog("How many rounds?");
		try {
			round = new Integer(info);
			if (round < 1) System.exit(0);
		} catch (NumberFormatException e) {
			System.err.println("Invalid number of rounds.");
			System.exit(0);
		}
		
		info = JOptionPane.showInputDialog("How many players?");
		try {
			players  = new Integer(info);
			if (players < 1) System.exit(0);
		} catch (NumberFormatException e) {
			System.err.println("Invalid number of players.");
			System.exit(0);
		}
		
		info = JOptionPane.showInputDialog("What is A?");
		try {
			A  = new Double(info);
			if (A < 0) System.exit(0);
		} catch (NumberFormatException e) {
			System.err.println("Invalid number for A.");
			System.exit(0);
		}
		
		info = JOptionPane.showInputDialog("What is B?");
		try {
			B  = new Double(info);
			if (B < 0) System.exit(0);
		} catch (NumberFormatException e) {
			System.err.println("Invalid number for B.");
			System.exit(0);
		}
		
		info = JOptionPane.showInputDialog("What is alpha?");
		try {
			alpha  = new Double(info);
			if (alpha < 0) System.exit(0);
		} catch (NumberFormatException e) {
			System.err.println("Invalid number for alpha.");
			System.exit(0);
		}
	}
}
